const mysql = require('mysql');

let c = mysql.createConnection({
    host: 'localhost',
    port: '3306',
    user: 'root',
    password: '304304',
    database: 'tedu'
});

let cPool = mysql.createPool({
    host: 'localhost',
    port: '3306',
    user: 'root',
    password: '304304',
    database: 'tedu',
    connectionLimit: 15
});

c.query('SELECT * FROM emp', (err, result) => {
    if(err) throw err;
    console.log(result);
});

cPool.query('SELECT * FROM emp WHERE eid = ?', [1], (err, result) => {
    if(err) throw err;
    console.log(result);
});

let emp = {
    ename: 'Jack',
    sex: '1',
    birthday: '2021-05-28',
    salary: 12000,
    deptId: 1
}

c.query('insert into emp (ename, sex, birthday, salary, deptId) values (?, ?, ?, ? ,?)', 
        [emp.ename, emp.sex, emp.birthday, emp.salary, emp.deptId], (err, result) => {
            if(err) throw err;
            console.log(result);
        });

cPool.query('insert into emp (ename, sex, birthday, salary, deptId) values (?, ?, ?, ? ,?)', 
[emp.ename, emp.sex, emp.birthday, emp.salary, emp.deptId], (err, result) => {
    if(err) throw err;
    console.log(result);
});